var serviceHttp = 'http://www.ihengtian.top:8101/';
// var serviceHttp = 'http://localhost:8101/';

// var shop_before = '/api/cft/shop';
var query_mine_info = '/query/mine/info';

var organ_before = '/api/cft/organ';
var query_job_level = '/shop/job/level/config';
var query_all_stuff='/query/all/stuffs';
var query_expand_shps = '/query/mine/expand/shops';
var query_stuff_target = '/query/mine/target';
var sell_shop_material = '/sell/shop/material';

var indexApp = angular.module('myApp', []);


indexApp.controller("myCtrl", function($http, $scope, $location) {

    $http({  
    	method:'post',  
   		url:serviceHttp + organ_before + query_all_stuff,  
    	data:{token:"ELGBLELDMCC",id:"246"}  
		}).success(function(response){  
			$scope.stuffs = response.data;
    		console.log(response);  
		})  
	
    
    $scope.queryExpand = function(token,id) {
        $http({  
        method:'post',  
        url:serviceHttp + organ_before + query_expand_shps,  
        data:{token:token,id:id}  
        }).success(function(response){ 
            if (response.data.length>0) {
                for (var i = 0; i < response.data.length; i++) {
                    if(response.data[i].type=="shop")
                        response.data[i].typeName="门店";
                    else    response.data[i].typeName="运营商";
                }
            }
            $scope.shops = response.data;
            $scope.message=response.message;
            console.log(response);  
        }) 
    };

    $scope.sendMaterial = function(shop) {
        $scope.currentShop=shop;
        $scope.sellData.shopId = shop.id;
        
    };

    $scope.queryTarget = function(stuff) {
        $scope.currentStuff=stuff;
        $scope.sellData.token = stuff.shopper.token;
        $scope.sellData.id = stuff.id;
        $http({  
        method:'post',  
        url:serviceHttp + organ_before + query_stuff_target,  
        data:{token:stuff.shopper.token,id:stuff.id}  
        }).success(function(response){ 
            $scope.currentTarget = response.data;
            console.log(response);  
        }) 
    };

    
    $scope.sellData = {token:"",id:"",shopId:"",
    materialId:1,number:"",pay:""};   

    $scope.sellMaterial = function() {
        if (!$scope.currentStuff.shopper||!$scope.currentShop.id) {
            alert("请点击人员销售情况并选择业务拓展中的门店")
        }else{
        $http({  
            method:'post',  
            url:serviceHttp + organ_before + sell_shop_material,  
            data:$scope.sellData 
            }).success(function(response){ 
            $scope.addmessage = response.message;
            alter(response.message);
            console.log(response);  
        })  
        }
        

    };

});